<?php 

// incluindo nosso arquivo customizer
require( get_template_directory() . '/inc/customizer.php');

// remove a exibicao da versao do wordpress
remove_action('wp_head', 'wp_generator');

// funcao carregando de scripts js e css
function carrega_scripts(){
  // bootstrap 
  wp_enqueue_style('boostrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', array(), '3.3.7', 'all');
  wp_enqueue_script('boostrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', array('jquery'), '3.3.7', true); 
  // array('jquery') - carrega a depedencia jquery antes do script ou css
  
  wp_enqueue_style('template', get_template_directory_uri() . '/css/template.css', array(), '1.0', 'all');

  wp_enqueue_script('template', get_template_directory_uri() . '/js/template.js', array(), null, true); 
  // true carregado no final do arquivo
}

add_action('wp_enqueue_scripts', 'carrega_scripts');

// funcao para menus
// https://codex.wordpress.org/Function_Reference/register_nav_menus
register_nav_menus(
  array(
    'meu_menu_pricipal' => 'Menu Principal',
    'menu_rodape' => 'Menu no Rodape',
    'meu_outro_menu' => 'Meu Outro Menu'
  )
  );


// adicionando suporte ao tema -  campos que usuario vai pode editar no tema facilmente
// https://developer.wordpress.org/reference/functions/add_theme_support/#custom-background
add_theme_support( 'custom-background' );
// https://developer.wordpress.org/reference/functions/add_theme_support/#custom-header
$defaults = array(
	'flex-width'             => true
);
add_theme_support( 'custom-header', $defaults );
// add_theme_support( 'custom-header' );

// adicionar suporte a imagem destacada  - miniatura de imagens
//https://developer.wordpress.org/reference/functions/add_theme_support/#post-thumbnails
add_theme_support( 'post-thumbnails' );

// adicionar o suporte a tipo de posts
// https://codex.wordpress.org/Post_Formats
// https://developer.wordpress.org/reference/functions/add_theme_support/#post-formats
add_theme_support( 'post-formats', array( 'video', 'image', 'aside', 'gallery' ) );


// registrando sidebars
// https://codex.wordpress.org/Function_Reference/register_sidebar
if(function_exists('register_sidebar')) {
  register_sidebar(
    array(
        'name'  =>  'Barra Lateral 1',
        'id'    =>  'sidebar-1',
        'description' =>  'Barra lateral da pagina home',
        'before_widget' => '<div class="widget-wrapper">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="widget-titulo">',
        'after_title'   => '</h2>' 
      )
    );
    register_sidebar(
    array(
        'name'  =>  'Barra Lateral 2',
        'id'    =>  'sidebar-2',
        'description' =>  'Barra lateral da pagina blog',
        'before_widget' => '<div class="widget-wrapper">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="widget-titulo">',
        'after_title'   => '</h2>' 
      )
    );
    register_sidebar(
    array(
        'name'  =>  'Redes Sociais',
        'id'    =>  'redes-sociais',
        'description' =>  'widgets para rede sociais',
        'before_widget' => '<div class="widget-wrapper">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="widget-titulo">',
        'after_title'   => '</h2>' 
      )
    );
}


// habilitar o suporte a html5 para deixar mais moderno o wordpress
// https://developer.wordpress.org/reference/functions/get_search_form/#user-contributed-notes
add_theme_support( 'html5', array( 'search-form' ) );

// alterar o numero de itens por pagina no blog
// https://developer.wordpress.org/reference/hooks/pre_get_posts/
function num_items_blog( $query ) {
  
  if( !is_admin() && $query->is_main_query() ) {
    
    if( is_home() ) {
      $query->set('posts_per_page', 2);      
    }
  }

}
add_action( 'pre_get_posts', 'num_items_blog', 1);

// shortcode para mostrar o telefone na pagina de contato
function mostra_telefone(){
  if(wp_is_mobile()){
    $resultado = '<div class="telefone"><p>Ligue agora: <a href="tel:055998864565">055 99886-4565</a> </p></div>';
  }
  return $resultado;
}
add_shortcode('meutelefone', 'mostra_telefone');
// https://www.smashingmagazine.com/2012/05/wordpress-shortcodes-complete-guide/

// https://developer.wordpress.org/themes/functionality/custom-logo/
add_theme_support( 'custom-logo', array(
    'height'      => 100,
    'width'       => 200,
) );

?>